package com.chinacoal.hr.levelimpl.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinacoal.hr.levelapi.entity.BizTravelEmp;
import com.chinacoal.hr.levelimpl.mapper.BizTravelEmpMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author: YunTao.Li
 * @create: 2019-11-27 12:13
 * @description:
 **/
@Component
public class BizTravelEmpDao {

    @Resource
    private BizTravelEmpMapper bizTravelEmpMapper;


    /**
     * 查询出差单下的随同人员
     *
     * @param condition :
     * @return : com.baomidou.mybatisplus.core.metadata.IPage<com.chinacoal.hr.levelimpl.entity.BizTravel>
     * @author : YunTao.Li
     * @date : 2019/11/19 2019/11/19
     */
    public List<BizTravelEmp> getBizTravelEmpsWithOutPage(Map<String, Object> condition) throws Throwable {

        String travelId = condition.get("travelId") != null ? condition.get("travelId").toString() : "";

        QueryWrapper queryWrapper = new QueryWrapper();
        if (StringUtils.isNotBlank(travelId)) {
            queryWrapper.eq("BIZ_TRAVEL_ID", travelId);
        }


        List<BizTravelEmp> bizTravelList = bizTravelEmpMapper.selectList(queryWrapper);

        return bizTravelList;
    }

    /**
     * 新增随同人员
     * @author : YunTao.Li
     * @date : 2019/11/27 2019/11/27
     * @param record :
     * @return : void
     */
    public void insertBizTravelEmp(BizTravelEmp record) throws Throwable {
        bizTravelEmpMapper.insert(record);
    }


    /**
     *删除出差申请单下的所有随同人员
     * @author : YunTao.Li
     * @date : 2019/11/27 2019/11/27
     * @param travelId :
     * @return : void
     */
    public void deleteBizTravelEmpByTravelId(String travelId) throws Throwable{
        QueryWrapper warpper = new QueryWrapper();
        warpper.eq("BIZ_TRAVEL_ID",travelId);
        bizTravelEmpMapper.delete(warpper);
    }

}
